using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;

public class ElevatorDisplay : MonoBehaviour
{
    private TextMeshPro textFloor;
    private TextMeshPro textStatus;
    private TextMeshPro textDirection;
    private ElevatorController elevatorController;

    private Color movingColor = Color.yellow;
    private Color boardingColor = Color.green;

    void Start()
    {
        this.elevatorController = FindObjectOfType<ElevatorController>();
        var children = GetComponentsInChildren<TextMeshPro>();
        foreach (var child in children)
        {
            switch (child.name)
            {
                case Defines.Floor:
                    this.textFloor = child;
                    break;
                case Defines.Status:
                    this.textStatus = child;
                    break;
                case Defines.Direction:
                    this.textDirection = child;
                    break;
            }
        }
    }

    void Update()
    {
        if (this.elevatorController != null)
        {
            this.textFloor.text = this.elevatorController.CurrentFloor.ToString();
            this.textStatus.text = Utility.EnumHelper.GetEnumDescription(typeof(ElevatorStatus), this.elevatorController.ElevatorStatus.ToString());
            this.textDirection.text = this.elevatorController.IsLifting() ? "↑" : "↓";

            switch (this.elevatorController.ElevatorStatus)
            {
                case ElevatorStatus.Moving:
                    this.textStatus.color = this.movingColor;
                    break;
                case ElevatorStatus.Boarding:
                    this.textStatus.color = this.boardingColor;
                    break;
            }
        }
    }
}
